<?php
// 获取维修员的历史完成任务
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");
if (!session_id()) {
    session_start();
}

if (empty($_GET['search'])) {
    $sql = "SELECT * FROM tb_fix_repairer 
    INNER JOIN tb_fixinfo_request ON tb_fix_repairer.fix_id = tb_fixinfo_request.fix_id
    AND tb_fix_repairer.r_id = '" . $_SESSION['REPAIRER']['r_id'] . "' 
    AND tb_fixinfo_request.fix_status = '2'
    ORDER BY tb_fix_repairer.r_date DESC";
} else {
    $search = $_GET['search'];
    $sql = "SELECT * FROM tb_fix_repairer 
    INNER JOIN tb_fixinfo_request ON tb_fix_repairer.fix_id = tb_fixinfo_request.fix_id
    AND tb_fix_repairer.r_id = '" . $_SESSION['REPAIRER']['r_id'] . "' 
    AND tb_fixinfo_request.fix_status = '2'
    AND tb_fixinfo_request.fix_id LIKE '%" . $search . "%'
    ORDER BY tb_fix_repairer.r_date DESC";
}

$result = mysqli_query($conn_DB, $sql);
if ($result) {
    $num = mysqli_num_rows($result);
    if ($num <= 0) {
        function show_history()
        {
            echo "<tr><td colspan='8'>暂无数据</td></tr>";
        }
    } else {
        if (empty($_GET['search'])) {
            function show_history()
            {
                global $result;
                while ($row = mysqli_fetch_object($result)) {
                    echo "
                    <tr>
                        <th scope='row'>" . $row->fix_id . "</th>
                        <td>" . $row->fix_name . "</td>
                        <td>" . $row->fix_sendtime . "</td>
                        <td>" . $row->fix_phone . "</td>
                        <td>" . $row->fix_area . "</td>
                        <td>" . $row->fix_type . "</td>
                        <td>" . $row->r_date . "</td>
                        <td>" . $row->fix_endtime . "</td>
                        <td><a href='r-showfix.php?fix_id=" . $row->fix_id . "'>查看</a></td>
                    </tr>";
                }
            }
        } else {
            while ($row = mysqli_fetch_object($result)) {
                echo "
                <tr>
                    <th scope='row'>" . $row->fix_id . "</th>
                    <td>" . $row->fix_sendtime . "</td>
                    <td>" . $row->fix_phone . "</td>
                    <td>" . $row->fix_area . "</td>
                    <td>" . $row->fix_type . "</td>
                    <td>" . $row->r_date . "</td>
                    <td>" . $row->fix_endtime . "</td>
                    <td><a href='r-showfix.php?fix_id=" . $row->fix_id . "'>查看</a></td>
                </tr>";
            }
        }
    }
}
